package surveybrain.common
{
  
   
  public class SBEmailValidator
  {
     
    function SBEmailValidator()
    {
      
    }
    
    
    public function isEmail(e:String):Boolean
    {
      /* mcn 10/5/07: below replaced since it rejects valid email addresses such as mm@m.com for one.
         to do: get flex validator working
      
      var emailExpression:RegExp = /^[a-z][\w.-]+@\w[\w.-]+\.[\w.-]*[a-z][a-z]$/i;
      return emailExpression.test(s);
      */
      
		var ok : String = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
		
		for(var i : int =0; i < e.length; i++)
		{
			if( ok.indexOf(e.charAt(i)) < 0 )
			{ 
				return false;
			}	
		} 
		
		var re1 : RegExp = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		var re2 : RegExp = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
			
		if ( !e.match(re1) && e.match(re2) ) 
			return true;		
		else
		   return false;
      
      
    } // end isEmail
    
    
  } // end class
  
}